<style lang="less">
    @import './login.less';
</style>

<template>
<div class="hold-transition login-page">
  <div class="login-box">
    <div class="login-logo">
      <a href="../../index2.html"><b>Vue</b> Login</a>
    </div>
    <div class="login-box-body">
      <p class="login-box-msg">Vue AdminLte Template</p>
      <form action="../../index2.html" method="post">
        <div class="form-group has-feedback">
          <input type="username" class="form-control" placeholder="用户名" v-model="user.username">
          <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
          <input type="password" class="form-control" placeholder="密码" v-model="user.password">
          <span class="glyphicon glyphicon-lock form-control-feedback"></span>
        </div>
        <div class="row">
          <div class="col-xs-8">
          </div>
          <div class="col-xs-4">
            <a href="#" class="btn btn-primary btn-block btn-flat" v-on:click="loginHandler">登录
            </a>
          </div>
        </div>
      </form>
    </div>
  </div>
</div>
</template>
<script>
import utils from '@/libs/utils'
import {router} from '@/router/index'
export default {
  name: 'Login',
  data () {
    return {
      user: {
        username: '',
        password: ''
      }
    }
  },
  methods: {
    loginHandler: function () {
      utils.post('/api/auth', this.user, function (d) {
        if (utils.success(d)) {
          utils.setCookie('Authorization', d.data)
          router.push('/home')
        } else {
          utils.msg(d.msg)
        }
      })
    }
  }
}
</script>
